package com.framework;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import javax.activation.MimetypesFileTypeMap;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.eportal.util.MD5;
import com.eportal.util.Tools;

public class ClientHttp {
    private static final Log log = LogFactory.getLog(ClientHttp.class);

    public static String httpRequest(String httpUrl, Map<String, String> params) {
        URL url;
        try {
            url = new URL(httpUrl);

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //构建请求参数
            StringBuffer sb = new StringBuffer();
            if (params != null) {
                String temp = "";
                for (Entry<String, String> e : params.entrySet()) {
                    sb.append(e.getKey());
                    sb.append("=");
                    sb.append(e.getValue());
                    sb.append("&");
                    if (!e.getKey().equals("method")) {
                        temp = temp + e.getValue();
                    }
                }
//		String sign=MD5.MD5Encode(temp+"jz");
//		sb.append("sign");
//		sb.append("=");
//		sb.append(sign);
//		log.info("MD5("+temp+")");
            }
            log.info("send_url:" + url);
            log.info("send_data:" + sb.toString());

            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Charset", "UTF-8");
            conn.setRequestProperty("ContentType", "text/xml;charset=utf-8");
            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            writer.write(sb.toString());
            writer.flush();
            writer.close();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp = "";
            StringBuffer buffer = new StringBuffer();
            while ((temp = reader.readLine()) != null) {
                buffer.append(temp);
            }
            //服务器返回的结果
            String result = buffer.toString();
            reader.close();
            return result;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
        	log.error("", e1);
        }
        return null;
    }

    public static String httpRequest(String httpUrl, Map<String, Object> params, String grm) {
        URL url;
        try {
            url = new URL(httpUrl);

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //构建请求参数
            StringBuffer sb = new StringBuffer();
            if (params != null) {
                String temp = "";
                for (Entry<String, Object> e : params.entrySet()) {
                    sb.append(e.getKey());
                    sb.append("=");
                    sb.append(e.getValue());
                    sb.append("&");
                    temp = temp + e.getValue();
                }
                String sign = MD5.MD5Encode(temp + grm);
                sb.append("sign");
                sb.append("=");
                sb.append(sign);
                log.info("MD5(" + temp + grm + ")");
            }
            log.info("send_url:" + url);
            log.info("send_data:" + sb.toString());

            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Charset", "UTF-8");
            conn.setRequestProperty("ContentType", "text/xml;charset=utf-8");
            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            writer.write(sb.toString());
            writer.flush();
            writer.close();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp = "";
            StringBuffer buffer = new StringBuffer();
            while ((temp = reader.readLine()) != null) {
                buffer.append(temp);
            }
            //服务器返回的结果
            String result = buffer.toString();
            reader.close();
            return result;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
        	log.error("", e1);
        }
        return null;
    }

    /**
     * 远程请求-参数用&相隔再加密
     *
     * @param httpUrl
     * @param params
     * @return
     */
    public static String httpRequest_(String httpUrl, Map<String, String> params) {
        URL url;
        try {
            url = new URL(httpUrl);

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //构建请求参数
            StringBuffer sb = new StringBuffer();
            if (params != null) {
                String temp = "";
                for (Entry<String, String> e : params.entrySet()) {
                    sb.append(e.getKey());
                    sb.append("=");
                    sb.append(e.getValue());
                    sb.append("&");
                    temp = temp + e.getValue() + "&";
                }
                temp = temp.substring(0, temp.length() - 1);
                String sign = MD5.MD5Encode(temp);
                sb.append("sign");
                sb.append("=");
                sb.append(sign);
                log.info("MD5(" + temp + ")");
            }
            log.info("send_url:" + url);
            log.info("send_data:" + sb.toString());

            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            //conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setRequestProperty("Charset", "UTF-8");
            conn.setRequestProperty("ContentType", "text/xml;charset=utf-8");
            OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
            writer.write(sb.toString());
            writer.flush();
            writer.close();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp = "";
            StringBuffer buffer = new StringBuffer();
            while ((temp = reader.readLine()) != null) {
                buffer.append(temp);
            }
            //服务器返回的结果
            String result = buffer.toString();
            reader.close();
            return result;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        return null;
    }

    /**
     * 上传图片
     *
     * @param urlStr
     * @param textMap
     * @param fileMap
     * @return
     */
    public static String formUpload(String urlStr, Map<String, String> textMap,
                                    Map<String, File> fileMap) {
        String res = "";
        HttpURLConnection conn = null;
        String BOUNDARY = "---------------------------123821742118716"; //boundary就是request头和上传文件内容的分隔符
        try {
            URL url = new URL(urlStr);
            conn = (HttpURLConnection) url.openConnection();
            conn.setConnectTimeout(5000);
            conn.setReadTimeout(30000);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn
                    .setRequestProperty("User-Agent",
                            "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
            conn.setRequestProperty("Content-Type",
                    "multipart/form-data; boundary=" + BOUNDARY);

            OutputStream out = new DataOutputStream(conn.getOutputStream());
            // text
            if (textMap != null) {
                StringBuffer strBuf = new StringBuffer();
                Iterator<?> iter = textMap.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String inputName = (String) entry.getKey();
                    String inputValue = (String) entry.getValue();
                    if (inputValue == null) {
                        continue;
                    }
                    strBuf.append("\r\n").append("--").append(BOUNDARY).append(
                            "\r\n");
                    strBuf.append("Content-Disposition: form-data; name=\""
                            + inputName + "\"\r\n\r\n");
                    strBuf.append(inputValue);
                }
                out.write(strBuf.toString().getBytes());
            }

            // file
            if (fileMap != null) {
                Iterator iter = fileMap.entrySet().iterator();
                while (iter.hasNext()) {
                    Map.Entry entry = (Map.Entry) iter.next();
                    String inputName = (String) entry.getKey();
                    File file = (File) entry.getValue();
                    if (file.length() <= 0) {
                        continue;
                    }
                    String filename = file.getName();
                    String contentType = new MimetypesFileTypeMap()
                            .getContentType(file);
                    if (filename.endsWith(".png")) {
                        contentType = "image/png";
                    }
                    if (contentType == null || contentType.equals("")) {
                        contentType = "application/octet-stream";
                    }

                    StringBuffer strBuf = new StringBuffer();
                    strBuf.append("\r\n").append("--").append(BOUNDARY).append(
                            "\r\n");
                    strBuf.append("Content-Disposition: form-data; name=\""
                            + inputName + "\"; filename=\"" + filename
                            + "\"\r\n");
                    strBuf.append("Content-Type:" + contentType + "\r\n\r\n");

                    out.write(strBuf.toString().getBytes());

                    DataInputStream in = new DataInputStream(
                            new FileInputStream(file));
                    int bytes = 0;
                    byte[] bufferOut = new byte[1024];
                    while ((bytes = in.read(bufferOut)) != -1) {
                        out.write(bufferOut, 0, bytes);
                    }
                    in.close();
                }
            }

            byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
            out.write(endData);
            out.flush();
            out.close();

            // 读取返回数据
            StringBuffer strBuf = new StringBuffer();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                strBuf.append(line).append("\n");
            }
            res = strBuf.toString();
            reader.close();
            reader = null;
        } catch (Exception e) {
            System.out.println("发送POST请求出错。" + urlStr);
            e.printStackTrace();
            log.error("", e);
        } finally {
            if (conn != null) {
                conn.disconnect();
                conn = null;
            }
        }
        return res;
    }

    public static String httpRequestGet(String httpUrl) {
        URL url;
        try {
            url = new URL(httpUrl);

            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
            String temp = "";
            StringBuffer buffer = new StringBuffer();
            while ((temp = reader.readLine()) != null) {
                buffer.append(temp);
            }
            //服务器返回的结果
            String result = buffer.toString();
            reader.close();
            return result;
        } catch (Exception e1) {
            // TODO Auto-generated catch block
        	log.error("", e1);
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
//		Map<String, String> params=new TreeMap<String, String>();
//		params.put("method", "register");
//		params.put("phone", "15990172599");
//		params.put("username", "15990172999");
//		params.put("name", "9999");
//		params.put("password", "123456");
//		params.put("email", "1111dd111@qq.com");
//		params.put("appkey", "d75344dd9f5b84823a581df14bb53ecd");
//		System.out.println(httpRequest("http://127.0.0.1:8080/sdk/webService/webService_index.action", params));
        //http://183.136.140.182:8080/sdk/webService/webService_index.action?method=appIAP&orderid=2014121122591667&pdtid=gems_60&receipt-data=ewoJInNpZ25hdHVyZSIgPSAiQW5xR2JRcjd3d0RJcll0dVgxQnFKeE5VNW9pRlA5OHQvcXN2bFFQZEIyZ3VWTUlLNWl6SEdyYUdxWWFPKzJJaWF2MjRxZUtqcFJEVmdndFB3aXMvTmM4QW5sendNYlhUTmVZcHRTQUtaZkhUZ3gxZUlJcnBiMjA3RCs4QXhOVnlPUitFMzAxaFR0QzE4Ujd2K2t2UUtVVjZJNFN5M3dHcll5dUU0allPS1dCU0FBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NCdX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Ym5ScFptbGxjaUlnUFNBaVJUVTFNakZFTURrdE1qSkVNQzAwTkRBM0xVSTNPRVV0TXpjME1VSXhSamRCUXpGR0lqc0tDU0p3Y205a2RXTjBMV2xrSWlBOUlDSm5aVzF6WHpZd0lqc0tDU0pwZEdWdExXbGtJaUE5SUNJNU5UQXlNemt5TkRNaU93b0pJbUpwWkNJZ1BTQWlZMjl0TG5ScFlXNXhhUzVrYW1GdVoyOGlPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVXRiWE1pSUQwZ0lqRTBNVGd6TURrME5ETXdNREFpT3dvSkluQjFjbU5vWVhObExXUmhkR1VpSUQwZ0lqSXdNVFF0TVRJdE1URWdNVFE2TlRBNk5ETWdSWFJqTDBkTlZDSTdDZ2tpY0hWeVkyaGhjMlV0WkdGMFpTMXdjM1FpSUQwZ0lqSXdNVFF0TVRJdE1URWdNRFk2TlRBNk5ETWdRVzFsY21sallTOU1iM05mUVc1blpXeGxjeUk3Q2draWIzSnBaMmx1WVd3dGNIVnlZMmhoYzJVdFpHRjBaU0lnUFNBaU1qQXhOQzB4TWkweE1TQXhORG8xTURvME15QkZkR012UjAxVUlqc0tmUT09IjsKCSJlbnZpcm9ubWVudCIgPSAiU2FuZGJveCI7CgkicG9kIiA9ICIxMDAiOwoJInNpZ25pbmctc3RhdHVzIiA9ICIwIjsKfQ==&appkey=b193784881836850bfbd006828f8828b&sign=021ab0ce6a0e6594c4d333baed47910c
        //http://183.136.140.182:8080/sdk/webService/webService_index.action?method=appIAP&orderid=20141212143534378&pdtid=gems_60&receipt-data=ewoJInNpZ25hdHVyZSIgPSAiQWx5cXhtQ3gwOU8xTVYzUXdrYk0ySmI1cVJJcGRlZHd5ek0vOEpxRXFmYktlRFFqTHhBNVpPV0YzTUpOUFRuelV2YmtnT1Q4UGNRSEd3N3F3RlV2WmdZVEhLM2FLQVpoaEt1dXNuRGU0MnNCYWtjTm8zOXRUWTFQZ2Z6dGg0YVl0R2N0L1VQNkZyTnE3OHYrYms3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dGJYTWlJRDBnSWpFME1UZ3pOall4TVRZM05qTWlPd29KSW5WdWFYRjFaUzEyWlc1a2IzSXRhV1JsYm5ScFptbGxjaUlnUFNBaVJUVTFNakZFTURrdE1qSkVNQzAwTkRBM0xVSTNPRVV0TXpjME1VSXhSamRCUXpGR0lqc0tDU0p3Y205a2RXTjBMV2xrSWlBOUlDSm5aVzF6WHpZd0lqc0tDU0pwZEdWdExXbGtJaUE5SUNJNU5UQXlNemt5TkRNaU93b0pJbUpwWkNJZ1BTQWlZMjl0TG5ScFlXNXhhUzVrYW1GdVoyOGlPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVXRiWE1pSUQwZ0lqRTBNVGd6TmpZeE1UWTNOak1pT3dvSkluQjFjbU5vWVhObExXUmhkR1VpSUQwZ0lqSXdNVFF0TVRJdE1USWdNRFk2TXpVNk1UWWdSWFJqTDBkTlZDSTdDZ2tpY0hWeVkyaGhjMlV0WkdGMFpTMXdjM1FpSUQwZ0lqSXdNVFF0TVRJdE1URWdNakk2TXpVNk1UWWdRVzFsY21sallTOU1iM05mUVc1blpXeGxjeUk3Q2draWIzSnBaMmx1WVd3dGNIVnlZMmhoYzJVdFpHRjBaU0lnUFNBaU1qQXhOQzB4TWkweE1pQXdOam96TlRveE5pQkZkR012UjAxVUlqc0tmUT09IjsKCSJlbnZpcm9ubWVudCIgPSAiU2FuZGJveCI7CgkicG9kIiA9ICIxMDAiOwoJInNpZ25pbmctc3RhdHVzIiA9ICIwIjsKfQ==&appkey=b193784881836850bfbd006828f8828b&appcallbackurl=http://121.41.55.194:26746&custompar=700002-15877-gems_60&sign=29f9af83ee9531583c256cc8e7e35ac4
        Map<String, String> params = new TreeMap<String, String>();
        params.put("method", "appIAP");
        params.put("orderid", "20141212113305983");
        params.put("pdtid", "gems_60");
        params.put("appcallbackurl", "http://121.41.55.194:26746");
        params.put("receipt-data", "ewoJInNpZ25hdHVyZSIgPSAiQW5xR2JRcjd3d0RJcll0dVgxQnFKeE5VNW9pRlA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anNLQ1NKMGNtRnVjMkZqZEdsdmJpMXBaQ0lnUFNBaU1UQXdNREF3TURFek5UTXdNRFl6TmlJN0Nna2ljWFZoYm5ScGRIa2lJRDBnSWpFaU93b0pJbTl5YVdkcGJtRnNMWEIxY21Ob1lYTmxMV1JoZEdVdGJYTWlJRDBnSWpFME1UZ3pNRGswTkRNd01EQWlPd29KSW5WdWFYRjFaUzEyWlc1a2IzSXRhV1JsYm5ScFptbGxjaUlnUFNBaVJUVTFNakZFTURrdE1qSkVNQzAwTkRBM0xVSTNPRVV0TXpjME1VSXhSamRCUXpGR0lqc0tDU0p3Y205a2RXTjBMV2xrSWlBOUlDSm5aVzF6WHpZd0lqc0tDU0pwZEdWdExXbGtJaUE5SUNJNU5UQXlNemt5TkRNaU93b0pJbUpwWkNJZ1BTQWlZMjl0TG5ScFlXNXhhUzVrYW1GdVoyOGlPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVXRiWE1pSUQwZ0lqRTBNVGd6TURrME5ETXdNREFpT3dvSkluQjFjbU5vWVhObExXUmhkR1VpSUQwZ0lqSXdNVFF0TVRJdE1URWdNVFE2TlRBNk5ETWdSWFJqTDBkTlZDSTdDZ2tpY0hWeVkyaGhjMlV0WkdGMFpTMXdjM1FpSUQwZ0lqSXdNVFF0TVRJdE1URWdNRFk2TlRBNk5ETWdRVzFsY21sallTOU1iM05mUVc1blpXeGxjeUk3Q2draWIzSnBaMmx1WVd3dGNIVnlZMmhoYzJVdFpHRjBaU0lnUFNBaU1qQXhOQzB4TWkweE1TQXhORG8xTURvME15QkZkR012UjAxVUlqc0tmUT09IjsKCSJlbnZpcm9ubWVudCIgPSAiU2FuZGJveCI7CgkicG9kIiA9ICIxMDAiOwoJInNpZ25pbmctc3RhdHVzIiA9ICIwIjsKfQ==");
        params.put("appkey", "b193784881836850bfbd006828f8828b");
        System.out.println(httpRequest("http://183.136.140.182:8080/sdk/webService/webService_index.action", params));
//		Map<String, String> params=new TreeMap<String, String>();
//		params.put("method", "aliPayMobilePay");
//		params.put("subject", "贝壳");
//		params.put("total_fee", "1");
//		params.put("body", "贝壳充值");
//		params.put("appkey", "571ad9c8cc1b5b91b8ac19f49096c083");
//		params.put("identityid", "10");
//		System.out.println(httpRequest("http://127.0.0.1:8080/sdk/webService/webService_index.action", params));
//	    String filepath="C:/Users/yz/Desktop/1380080903400.jpg";
//	    Map<String, String> param=new HashMap<String, String>();
//		param.put("method", "avatarupload");
//		param.put("uid", "3");
//		Map<String, File> fileMap = new HashMap<String, File>();
//		fileMap.put("avatars", new File(filepath));
//		String ret = formUpload("http://127.0.0.1:8080/beike/webService/webService_index.action", param, fileMap);
//		System.out.println(ret);
        // TODO Auto-generated method stub
        //System.out.println(URLEncoder.encode(RSA.sign("_input_charset=\"UTF-8\"&app_id=\"12\"&appenv=\"56\"&body=\"测试\"&it_b_pay=\"45m\"&notify_url=\"http%3A%2F%2F183.136.140.182%3A8080%2Fsdk%2Fweb%2Fcallback_aliPayMobilePayRet.action\"&out_trade_no=\"20140925020410261\"&partner=\"2088512640731090\"&payment_type=\"1\"&seller_id=\"beikecard@126.com\"&service=\"mobile.securitypay.pay\"&show_url=\"http\"&subject=\"支付宝\"&total_fee=\"10\"",
        //		"MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALgz9a4BoSCiqp4ENIiY7YTH5fFatYqkLNig1MHx7ARP1OnYW2zdxt5ck1yM0NIjrbozDaNiCJ60qPAjcD/uPsdESxc0VAylXFASc50zwSWkgu0Y0lvqwrQPjE2DPfNvtYDwz1Djc47JFECu+XLEhBVTaCm/41KjbmepdoXVJN5XAgMBAAECgYA3E/JGEV6ob3ssvH0oyvFaXps2y7S0u9pc+9oiE8BKmcREF9leeAHawzuc1M4rx1dO8a0GSW3iZoqNI0uREh/a2zqAWGI28mvtNbIBhR54dI3lki81Ui17KkEct5E5bIklLZaviyvENkAgb8kf6ST4NaWBwbFoFgyvcQABoC09YQJBAOh6oTjC4ABQYwrOLeqeifm/LonRe18FP0LphbAW2/MBOHGC1zlVPjBoE2Xm37fDukrbvsKOKsXSHHnd5/4/TZsCQQDK1vI1bsyJ1g4jgjmGsT7E91hYfZ4cZiwCxN1YYQe8NqNwQDuPh4NqKSMYxJzy35Y0a7a35VubFEDD2jcaRNv1AkAfz+gP5FrSsC1dZSlTWa53xnmP0mKXdhhaB6qLlhUzA4+9uLHK3qdL6HH/F8C1XMs5QyivZtTjjQToiD0exXrRAkBkgiG+bEqZuiGDYtHSdh1eSBnUr1obRF1medocIuhMUN6njox00HdDsWKcsT/78OJi00TU1qePrndxFL3dHGXJAkEAoXeLCg4gHyJ1sBGhnARfxGGGlCcFOenBo4V50AAV84qPFcTSNWa21IUiQwoVIFqwKRN6khEjGFk/efAWauoeMw==", "UTF-8"), "UTF-8"));
        //System.out.println(Float.valueOf(10/100));
        //System.out.println(URLEncoder.encode(RSA.decrypt("V28Y373NK+B+b3vpVqVjJz/Y0TIaMFbFYJ6qC3MEY/Oc+N2gUULceaGkmpxwSI8Kc5D03eSS89d9AFHohJ4xKkyFHdZ87N92RjfDf5mERRrGtb481ZZYAM4A1vZc+4RUfmX0ZGIEPsiDSVWNrQBBfp+g5Dnf76ZSDeqNDP0ivKY=", "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALgz9a4BoSCiqp4ENIiY7YTH5fFatYqkLNig1MHx7ARP1OnYW2zdxt5ck1yM0NIjrbozDaNiCJ60qPAjcD/uPsdESxc0VAylXFASc50zwSWkgu0Y0lvqwrQPjE2DPfNvtYDwz1Djc47JFECu+XLEhBVTaCm/41KjbmepdoXVJN5XAgMBAAECgYA3E/JGEV6ob3ssvH0oyvFaXps2y7S0u9pc+9oiE8BKmcREF9leeAHawzuc1M4rx1dO8a0GSW3iZoqNI0uREh/a2zqAWGI28mvtNbIBhR54dI3lki81Ui17KkEct5E5bIklLZaviyvENkAgb8kf6ST4NaWBwbFoFgyvcQABoC09YQJBAOh6oTjC4ABQYwrOLeqeifm/LonRe18FP0LphbAW2/MBOHGC1zlVPjBoE2Xm37fDukrbvsKOKsXSHHnd5/4/TZsCQQDK1vI1bsyJ1g4jgjmGsT7E91hYfZ4cZiwCxN1YYQe8NqNwQDuPh4NqKSMYxJzy35Y0a7a35VubFEDD2jcaRNv1AkAfz+gP5FrSsC1dZSlTWa53xnmP0mKXdhhaB6qLlhUzA4+9uLHK3qdL6HH/F8C1XMs5QyivZtTjjQToiD0exXrRAkBkgiG+bEqZuiGDYtHSdh1eSBnUr1obRF1medocIuhMUN6njox00HdDsWKcsT/78OJi00TU1qePrndxFL3dHGXJAkEAoXeLCg4gHyJ1sBGhnARfxGGGlCcFOenBo4V50AAV84qPFcTSNWa21IUiQwoVIFqwKRN6khEjGFk/efAWauoeMw==", "UTF-8"), "UTF-8"));
        //System.out.println((float)2/(float)3);
    }

}
